﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Entry;

namespace COFE.Core.Actions
{
    public static class IPropertyImplementerExtension
    {
        #region Action

        public static object[] GetSupportedAction<T>(this IPropertyImplementer<T> implementer)
        {
            return implementer.GetSupportedProperty(PropertyRetrivalOptions.NotApplied,
                MatchMode.Any, new ActionPropertyFilter());
        }

        public static bool IsActionSupported<T>(this IPropertyImplementer<T> implementer, 
            object action)
        {
            return implementer.GetSupportedAction().Contains(action);
        }

        public static Func<IEntryList, string, IWorkProgress, IEntryList> GetAction<T>(
            this IPropertyImplementer<T> implementer, object action)
        {
            if (action == null)
                throw new NullReferenceException();
            var pp = implementer.GetProperty(action, PropertyRetrivalOptions.NotApplied);
            if (pp == null)
                throw new NotSupportedException();

            return (Func<IEntryList, string, IWorkProgress, IEntryList>)
                implementer.GetProperty(action).Value;
        }

        #endregion

    }
}
